home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Sound / Utilities / ST201MusicDrivers Folder / Music Drivers / Simple Trecker.c < prev    next >
C/C++ Source or Header  |  1993-12-19  |  5KB  |  151 lines

  1.  
  2. /*** Simple Trecker.c ***/
  3.  
  4. /* Demonstration program to show how to use the Sound-Trecker Sound System V2.0.1. */
  5.  
  6. /* Frank Seide, 12/18/1993 */
  7.  
  8. /*
  9.    Copyright (c) 1991-93 by
  10.       Frank Seide
  11.       Wirichsbongardstr. 43
  12.       D-52062 Aachen
  13.       Germany
  14. */
  15.  
  16. /*
  17.    The 'PSTk' and 'ISTk' resources as well as this example source code may be used
  18.    freely in public domain programs under the conditions given in “The Sound-Trecker V2.0:
  19.    Licence Agreement”, e.g.:
  20.    • the resources themselves are copyrighted and not in the public domain!
  21.      The public domain program and the documentation must contain a copyright notice
  22.      like above, my address must be mentioned;
  23.    • you must send me one copy of the program;
  24.    • the code resources may not be modified (if you should find a bug, please tell me
  25.      to fix it. It´s important not to have too many different versions of the code);
  26.    • any kind of commercial use is forbidden and requires a special licence aggreement.
  27.    • for the exact details, see “The Sound-Trecker V2.0: Licence Agreement”
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <sound.h>
  32. #include "PSyn.h"
  33. #include "STrI.h"
  34.  
  35. main()
  36. {
  37.     /* The program requires the Sound Manager of System 7 (contained in System 6.0.7 */
  38.     /* and above). The 'PSyn' code verifies this before opening the sound channel. */
  39.     /* You may want to do this verification in the main program to provide user feedback */
  40.     /* (not shown in this example). */
  41.     /* A 68020 is no longer required (as in V1.0). However, for 68000 Macs, an ASC */
  42.     /* is required, as in the Portable and the Powerbook 100. This is a problem of the */
  43.     /* Sound Manager. */
  44.  
  45.     /* Variables: */
  46.     int i;
  47.     PChannelPtr pc = NULL;            /* Sound-Trecker Sound System Descriptor */
  48.     SoundTrackHandle strk = NULL;    /* Handle to current MOD */
  49.  
  50.     /* Constants: */
  51.     const Boolean stereo = FALSE;            /* Stereo ? */
  52.     const Boolean fadeOut = TRUE;            /* fade out on stop ? */
  53.     const Boolean realTimeFilter = FALSE;    /* use real time filter ? */
  54.     const Boolean preFilter = TRUE;            /* prefilter at load time ? */
  55.     const Fixed sampleRate = rate22khz;        /* output sample rate */
  56.  
  57.     /* Initialize the Mac OS: */
  58.  
  59.     InitGraf (&thePort);
  60.     InitFonts();
  61.     FlushEvents (everyEvent, 0);
  62.     InitWindows();
  63.     InitMenus();
  64.     TEInit();
  65.     InitDialogs (NULL);
  66.      InitCursor();
  67.  
  68.     /* Open the Sound-Trecker Sound System (limit to 32 voices; 16 bit if available): */
  69.  
  70.     if (OpenPChannel (32, (stereo ? opc_stereo : 0) + opc_16Bit, 820*8, &pc)) {
  71.         SysBeep (30); exit();
  72.     }
  73.  
  74.     /* Set the output sample rate (OpenPChannel() defaults to 22 kHz). */
  75.     /* Note always to stop playing before changing the sample rate. */
  76.     /* Warning: the old variable pc->softFreq of V1.0 no longer exists in V2.0 */
  77.  
  78.     pc->hardFreq = sampleRate;
  79.  
  80.     /* Change Sound System options: */
  81.     pc->antiAlias = realTimeFilter;        /* Apply real time filter ? */
  82.     pc->userMixing = FALSE;                /* Default channel mixing */
  83.     pc->noSurround = stereo;            /* Allow for stereo surround effects */
  84.  
  85.     /* Set channel volumes and the total volume. This could be left out in this example, */
  86.     /* because the volumes are initialized by OpenPChannel() exactly as we do here. */
  87.     /* The channel volumes are ignored, if pc->userMixing = FALSE (as in this example). */
  88.     /* The volumes may also be changed with this call, when the Sound System is playing. */
  89.  
  90.     for (i = 0; i < 32; i++) PChannelVolume (pc, i, 0x10000);    /* Fixed 0x10000 = 100% */
  91.     PChannelVolume (pc, -1, 0x08000);    /* -1 = Gesamtlautst. / -1 denotes total volume */
  92.  
  93.     /* Main event loop: */
  94.  
  95.     while (TRUE) {
  96.  
  97.         /* Let the user select a MOD file with a standard file dialog: */
  98.  
  99.         SFTypeList theTypeList = { 'STrk' };
  100.         StandardFileReply theReply;
  101.  
  102.         StandardGetFile (NULL, 1, theTypeList, &theReply);
  103.  
  104.         /* Quit main loop if user selects “Cancel”: */
  105.  
  106.         if (!theReply.sfGood) { StopPChannel (pc, fadeOut); break; }
  107.  
  108.         /* Stop the current MOD if there is one: */
  109.  
  110.         if (strk) {                            /* Is there a MOD to be stopped ?  */
  111.             StopPChannel (pc, fadeOut);        /* fade out & stop */
  112.             UnlinkSoundTrack (strk);        /* unlink MOD from Sound System */
  113.             DisposeSoundTrack (strk);        /* now free memory occupied by MOD */
  114.             strk = NULL;                    /* no MOD any more */
  115.         }
  116.  
  117.         /* Now load the MOD the user selected: */
  118.  
  119.         if (FSpGetSoundTrack (&theReply.sfFile, preFilter ? 1 : 0, &strk, FALSE))
  120.             SysBeep (30);                    /* (Load error) */
  121.         else {
  122.  
  123.             /* Change MOD options: */
  124.             /* Warning: access workspace variables only using GetSoundTrackWorkspace() */
  125.  
  126.             GetSoundTrackWorkspace (strk)->loopDetect = TRUE;
  127.  
  128.             /* Link MOD to Sound System: */
  129.  
  130.             LinkSoundTrack (strk, pc);
  131.  
  132.             /* At this point, in Simple Trecker V1.0 the total volume was reset to 50%, */
  133.             /* because it became zero due to fading out. Resetting the volume is */
  134.             /* no longer necessary in V2.0. */
  135.             /* PChannelVolume (pc, -1, 0x08000);    (Not required any more) */
  136.  
  137.             /* Reset song pointers to start: */
  138.  
  139.             ResetPChannel (pc);
  140.  
  141.             /* Start Sound System: */
  142.  
  143.             if (StartPChannel (pc)) { SysBeep (30); break; }
  144.         }
  145.     }
  146.  
  147.     /* Close the Sound System (required on System 6.0.7!): */    
  148.  
  149.     ClosePChannel (pc);
  150. }
  151.